package com.zmz.Stream;

import com.zmz.lambda.Item2;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/31/0:15
 * @Description:  Stream流对集合的筛选    基础操作体验
 */
public class Sream01 {
    public static void main(String[] args) {
        List<Item2> list = new ArrayList<>();
        list.add(new Item2(1, "阿萨", 10.22));
        list.add(new Item2(2, "撒旦", 20.21));
        list.add(new Item2(3, "答案", 22.22));
        //以前对集合元素的筛选
        List<Item2> list2 = new ArrayList<>();
        for(Item2 item2:list){
            if(item2.getId()==1||item2.getId()==2){
                list2.add(item2);
                System.out.println(item2);
            }
        }
        //使用Stream流对集合的筛选
        List<Item2> list1=list.stream().filter(t->t.getId()==1||t.getId()==2).collect(Collectors.toList());
        list1.forEach(t->System.out.println(t));


    }
}
